import { createApp } from "vue";
import axios from "axios";
import router from "./router";
import store from "./store";

import App from "./App.vue";

// axios.defaults.baseURL = "http://localhost:7001/api/";
axios.defaults.baseURL = "https://www.fastmock.site/mock/cfd691a5601b677b18fe7652740772f6/zheye";
axios.interceptors.request.use(config => {
  store.commit("setLoading", true);
  store.commit("setError", { status: false, message: "" });
  return config;
});
axios.interceptors.response.use(
  config => {
    setTimeout(() => {
      store.commit("setLoading", false);
    }, 1000);
    return config;
  },
  e => {
    const { error } = e.response.data;
    store.commit("setError", { status: true, message: error });
    store.commit("setLoading", false);
    return Promise.reject(e.response.data);
  },
);

const app = createApp(App);
app.use(router);
app.use(store);
app.mount("#app");
